public class isPalindrome {
    public boolean isPalindrome(String s) {
        int i = 0, j = s.length()-1;
        char a,b;
        while(i < j) {
        	while(i<s.length() && !Character.isLetterOrDigit(s.charAt(i))) i++;
        	while(j>-1 && !Character.isLetterOrDigit(s.charAt(j))) j--;
        	if(i==s.length() && j == -1) return true;
        	else if(i==s.length() || j==-1) return false;
        	a = s.charAt(i++);
        	b = s.charAt(j--);
        	if(Character.isUpperCase(a)) a = Character.toLowerCase(a);
        	if(Character.isUpperCase(b)) b = Character.toLowerCase(b);
        	if(a!=b) return false;
        }
        return true;
    }
    public static void main(String args[]) {
        String s = "Race a car";
        Solution ss = new Solution();
        System.out.println(ss.isPalindrome(s));
    }
}
